
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<script type="text/javascript" src="js/jquery.js"></script>
<body>
<form action="">
<div>
<table id="tab" style="  border:1px ;width:20%; border-collapse: collapse; ">
<tr style="background:#9CC">
<th>用户名</th>
<th>密码</th>
<th>昵称</th>
<th><span ></span>操作</th>
</tr>
<tbody id="tbody">


</tbody>

 

</table>
</div>
</form>
<a href="add.jsp">添加</a>


<a href="select.jsp">查找</a>
 <div id="pagecount" ></div> 
</body>

<script type="text/javascript">

$(function(){

	getData(1);
	
});

function del(num){
 
    $.ajax( {
         url:"/del",//url处理页面的地址
        data:"id="+num,//data传递的数据:"提交的数据"
        type:"POST",//POST的提交方式
       /*  dataType:"json", */
        success:function(result){
         alert("删除成功");
          $("#"+num).remove();
      
        },
        error:function(result){
        alert(1);
        }
      
        } );
}

    var curPage = 1; //当前页码
    var total,pageSize,totalPage;
    function getData(page){
$.ajax({
type:"post",
url:"/page",
data:"pagenum="+page,
 dataType:"json", 
 success:function(json){
  $("#tbody").empty();//清空数据区
                total = json.total; //总记录数
                pageSize = json.size; //每页显示条数
                curPage = page; //当前页
                totalPage = json.pagecount; //总页数
                var li = "";
                var list = json.list;
                for(var i=0;i<list.length;i++){
                $("#tbody").append("<tr style='background:#9CC'><td>"
                +list[i].name+"</td><td>"
                +list[i].pwd+"</td><td>"
                +list[i].nickname
                +"</td><td><a href='update'>更新</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='del("+list[i].id
                +")'>刪除</a>&nbsp;&nbsp;<a href='select?id="+list[i].id
                +"'>详情</a></td>");
                }
               
 
 
 },
 error:function(data){
 alert("shibai");
 },
 complete:function(){ //生成分页条
                getPageBar();
                /* fun(); */
            }

});
 function getPageBar(){
        //页码大于最大页数
        if(curPage>totalPage) curPage=totalPage;
        //页码小于1
        if(curPage<1) curPage=1;
        pageStr = "<span>共"+total+"条</span><span>"+curPage
        +"/"+totalPage+"</span>";
         
        //如果是第一页
        if(curPage==1){
            pageStr += "<span>首页</span><span>上一页</span>";
        }else{
            pageStr += "<span><a onclick='page(1)' href='javascript:void(0)' rel='1'>首页</a></span><span><a onclick='page("+(curPage-1)+")' href='javascript:void(0)' rel='"+(curPage-1)+"'>上一页</a></span>";
        }
         
        //如果是最后页
        if(curPage>=totalPage){
            pageStr += "<span>下一页</span><span>尾页</span>";
        }else{
            pageStr += "<span><a  onclick='page("+(curPage+1)+")'  rel='"+(parseInt(curPage)+1)+"'  href='javascript:void(0)'  > 下一页</a></span><span><a onclick='page("+totalPage+")' href='javascript:void(0)' rel='"+totalPage+"'>尾页</a></span>";
        }
        $("#pagecount").html(pageStr);
    }
    
    
  /*   function fun(){
    alert(222);
        $("#pagecount span a").on('click',function(){
            var rel = $(this).attr("rel");
            alert(rel);
            if(rel){
                getData(rel);
            };
        });  
    };  */
    
};
 function page(num){
    getData(num);
    }; 
   


</script>
</html>
